package com.budwk.app.sqfw.controllers.admin;

import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfw.dto.AssistanceDraftQueryDTO;
import com.budwk.app.sqfw.dto.AssistanceFormSummaryDTO;
import com.budwk.app.sqfw.services.AssistanceFormSummaryDraftService;
import com.budwk.app.sqfw.vo.ThreeGuaranteeVO;
import com.budwk.starter.common.openapi.annotation.ApiDefinition;
import com.budwk.starter.common.openapi.annotation.ApiOperation;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.security.utils.SecurityUtil;
import lombok.extern.slf4j.Slf4j;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.POST;
import org.nutz.mvc.annotation.Param;

import java.util.List;

/**
 * @author ZY.Wang
 * @since 2024/4/19
 */
@IocBean
@At("platform/assistance/formSummaryDraft")
@ApiDefinition(tag = "社区助手 草稿")
@Slf4j
public class AssistanceFormSummaryDraftController {

    @Inject
    private AssistanceFormSummaryDraftService draftService;

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "插入草稿")
    public Result<?> insertDraft(@Param("..") AssistanceFormSummaryDTO formSummaryDTO) {
        draftService.insertDraft(formSummaryDTO);
        return Result.success();
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "更新草稿")
    public Result<?> updateDraft(@Param("..") AssistanceFormSummaryDTO formSummaryDTO) {
        draftService.updateDraft(formSummaryDTO);
        return Result.success();
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "查询用户的草稿")
    public Result<?> listUserDraft(@Param("..") AssistanceDraftQueryDTO queryDTO) {
        String userId = SecurityUtil.getUserId();
        List<ThreeGuaranteeVO> list = draftService.listUserDraft(userId, queryDTO);
        return Result.success(list);
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "查询草稿详情")
    public Result<?> detailDraft(@Param("id") String id) {
        JSONObject vo = draftService.detailDraft(id);
        return Result.success(vo);
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "删除草稿")
    public Result<?> deleteDraft(@Param("id") String id) {
        draftService.deleteDraft(id);
        return Result.success();
    }
}
